package weaver.jobs.autolink.duss.cron;

import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.schedule.BaseCronJob;
import weaver.jobs.autolink.duss.utils.AutolinkUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * @Title: ecology-idea
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2022-09-02
 * @Description: 2、工作日报流程每天早上八点触发，安全级别小于等于11的不触发，（工时发生日期）=当前日期-1；
 * 3、检验请假流程，请假流程归档后，请假当天不触发请假工作日报；
 * 4、周末加班，加班申请单归档并且有打卡记录，触发工作日报 ；
 * @ModifyLog:
 **/

public class WeaScgzrblcCronJob extends BaseCronJob {
    @Override
    public void execute() {
        String currentDate = DateUtil.getCurrentDate();
        String yesterday = DateUtil.addDate(currentDate, -1);
        BaseBean baseBean = new BaseBean();
        baseBean.writeLog(">>>>WeaScgzrblcCronJob>>>>>currentDate=" + currentDate);
        RecordSet rs = new RecordSet();
        AutolinkUtil autolink = new AutolinkUtil();
        String sql = "select a.id,a.departmentid from hrmresource a join  cus_fielddata b on a.id=b.id " +
                     " where (b.scope='HrmCustomFieldByInfoType' and b.scopeid=-1 and b.field43 !=1) " +
                     " and a.seclevel>11 and a.status in (0,1,2,3) group by a.id,a.departmentid";
        rs.executeQuery(sql);
        while (rs.next()) {
            Map<String, String> requestMainMap = new HashMap<>();
            String resourceid = Util.null2String(rs.getString("id"));
            String departmentid = Util.null2String(rs.getString("departmentid"));
            requestMainMap.put("sqr",resourceid);
            requestMainMap.put("sqbm",departmentid);
            requestMainMap.put("gsfsrq",yesterday);
            baseBean.writeLog(">>>>WeaScgzrblcCronJob>>>>>resourceid=" + resourceid+",yesterday="+yesterday);
            boolean qjlcStatus = autolink.hasQjlc(resourceid, yesterday);
            baseBean.writeLog(">>>>WeaScgzrblcCronJob>>>>>qjlcStatus=" + qjlcStatus);
            boolean isWorkDay = autolink.isWorkDay(yesterday);
            baseBean.writeLog(">>>>WeaScgzrblcCronJob>>>>>isWorkDay=" + isWorkDay);
            if (qjlcStatus && isWorkDay) {
               String newrequestid = autolink.createGzrbWf(resourceid,yesterday,requestMainMap);
                baseBean.writeLog(">>>>WeaScgzrblcCronJob>>>>>newrequestid=" + newrequestid);
            }
            boolean jblcStatus = autolink.hasJblc(resourceid, yesterday);
            boolean signStatus = autolink.isScheduleSign(resourceid, yesterday);
            baseBean.writeLog(">>>>WeaScgzrblcCronJob>>>>>jblcStatus=" + jblcStatus+",signStatus="+signStatus);
            if (jblcStatus && signStatus) {
                String newrequestid = autolink.createGzrbWf(resourceid,yesterday,requestMainMap);
                baseBean.writeLog(">>>>WeaScgzrblcCronJob>>>>>newrequestid=" + newrequestid);
            }
        }

    }


}
